package com.mail.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mail.dubbo.mapper.UmsResourceCategoryMapper;
import com.mail.model.db.UmsResourceCategory;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author 吕永乐
 * @date 2022/06/23 11:34
 **/
@DubboService
public class UmsResourceCategoryApiImpl implements UmsResourceCategoryApi {

    @Autowired
    private UmsResourceCategoryMapper umsResourceCategoryMapper;

    /**
     * 查询所有后台资源分类
     *
     * @return
     */
    @Override
    public List<UmsResourceCategory> getAll() {
        return umsResourceCategoryMapper.getAll();
    }

    @Override
    public void create(UmsResourceCategory category) {
        category.setCreateTime(LocalDateTime.now());
        umsResourceCategoryMapper.insert(category);
    }

    // 根据ID删除后台资源
    @Override
    public void deleteCategoryById(Long id) {
        umsResourceCategoryMapper.deleteById(id);
    }

    // 修改后台资源分类
    @Override
    public void updateCategoryById(Long id, UmsResourceCategory resourceCategory) {
        LambdaQueryWrapper<UmsResourceCategory> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UmsResourceCategory::getId, id);
        umsResourceCategoryMapper.update(resourceCategory, wrapper);
    }
}
